package com.huawei.appgallery.splashscreen.ui;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnSystemUiVisibilityChangeListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.splashscreen.api.ISplashScreenFragmentProtocol;
import com.huawei.appgallery.splashscreen.impl.cache.FragmentCacheBean;
import com.huawei.appmarket.support.video.VideoPlayer;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import o.azb;
import o.cdn;
import o.cdo;
import o.cgv;
import o.cgy;
import o.cym.e;
import o.cyn;
import o.cyp;
import o.cyq;
import o.cyr;
import o.cyu;
import o.cyx;
import o.czc;
import o.czd;
import o.cze;
import o.czh;
import o.czj;
import o.epr;
import o.epv;
import o.ActivityUtil;
import o.evp.b;

@FragmentDefine(alias = "SplashScreenFragment", protocol = ISplashScreenFragmentProtocol.class)
public class SplashScreenFragment extends Fragment implements OnClickListener {
    private int ʹ;
    private cze ʻˊ;
    private String ʻˋ;
    private final BroadcastReceiver ʻᐝ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ SplashScreenFragment ˊ;

        {
            this.ˊ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (intent != null) {
                if ("android.intent.action.CLOSE_SYSTEM_DIALOGS".equals(intent.getAction()) && TextUtils.equals(intent.getStringExtra("reason"), "homekey") && this.ˊ.ॱˋ() != null) {
                    if (this.ˊ.ʽ != null) {
                        this.ˊ.ʽ.ˎ();
                    }
                    this.ˊ.ॱˋ().finish();
                }
            }
        }
    };
    private String ʼ;
    private ImageView ʼˊ;
    private String ʼˋ;
    private czc ʽ;
    private long ˊ = 2000;
    private long ˋ;
    private long ˎ;
    private cyp ˏ;
    private cyu ॱ;
    private int ॱॱ;
    private int ᐝ;
    private String ﹳ;
    private TextView ﾞ;
    private VideoPlayer ﾟ;

    static class c implements OnSystemUiVisibilityChangeListener {
        private final View ˊ;
        private final int ˎ;

        public c(View view, int i) {
            this.ˊ = view;
            this.ˎ = i;
        }

        public void onSystemUiVisibilityChange(int i) {
            if ((i & 4) == 0 && this.ˊ != null) {
                this.ˊ.setSystemUiVisibility(this.ˎ);
            }
        }
    }

    @Nullable
    public View ˋ(LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, Bundle bundle) {
        View view = null;
        this.ॱ = cyr.ˏॱ();
        if (this.ॱ != null) {
            this.ˏ = this.ॱ.ॱॱ();
            if (this.ॱ.ᐝ() != ᐝॱ().getConfiguration().orientation) {
                cyq.ˋ.ˋ("SplashScreenFragment", "screen orientation changed");
            } else if (this.ॱ.ʽ() != epv.ʽ(cyn.ॱ())) {
                cyq.ˋ.ˋ("SplashScreenFragment", "screen size changed");
            }
            return view;
        }
        Activity ॱˋ = ॱˋ();
        if (ॱˋ == null) {
            cyq.ˋ.ˏ("SplashScreenFragment", "activity is null");
            czh.ˋ(this.ˏ, 9);
        } else {
            ˋ(ॱˋ);
            if (this.ॱ != null) {
                this.ॱ.ˏ();
                FragmentCacheBean ˊ = this.ॱ.ˊ();
                if (ˊ != null) {
                    this.ᐝ = ˊ.ˋ();
                    this.ॱॱ = ˊ.ॱ();
                    this.ʼ = ˊ.ˎ();
                    this.ﹳ = ˊ.ᐝ();
                    this.ʹ = ˊ.ˏ();
                    this.ʼˋ = ˊ.ʽ();
                    this.ʻˋ = ˊ.ॱॱ();
                    cyq.ˋ.ˋ("SplashScreenFragment", "The showing splash screen id is " + ˊ.ᐝ());
                } else {
                    this.ᐝ = 0;
                    this.ॱॱ = 0;
                    this.ʼ = "";
                    this.ﹳ = "";
                    this.ʹ = -1;
                    this.ʼˋ = "";
                    this.ʻˋ = "";
                }
            }
            if (this.ʹ != 0) {
                if (cdn.ॱॱ()) {
                    czh.ˋ(this.ˏ, 9);
                    czh.ˎ(this.ˏ);
                } else {
                    try {
                        ॱˋ.setRequestedOrientation(1);
                    } catch (Throwable e) {
                        cyq.ˋ.ˊ("SplashScreenFragment", " Exception.", e);
                    }
                    if (2 == ᐝॱ().getConfiguration().orientation) {
                        czh.ˋ(this.ˏ, 9);
                        czh.ˎ(this.ˏ);
                    }
                }
            }
            if (2 == this.ʹ) {
                view = layoutInflater.inflate(e.ˊ, viewGroup, false);
                ˎ(view);
            } else {
                view = layoutInflater.inflate(e.ˎ, viewGroup, false);
                ˋ(view);
            }
            ˊ(view);
            ॱ();
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.intent.action.CLOSE_SYSTEM_DIALOGS");
            ActivityUtil.registerReceiver(ॱˋ(), intentFilter, this.ʻᐝ);
            this.ˎ = System.currentTimeMillis();
            if (this.ˏ != null) {
                this.ˏ.ˋ(this.ʼ, this.ﹳ, this.ʹ);
            }
            cyq.ˋ.ˎ("SplashScreenFragment", "show FestivalImage success");
        }
        return view;
    }

    public void ˌ() {
        super.ˌ();
        Activity ॱˋ = ॱˋ();
        if (ॱˋ != null) {
            ˋ(ॱˋ);
        }
    }

    public void ag_() {
        super.ag_();
        if (this.ˏ != null) {
            this.ˏ.ॱ(this.ʼ, this.ﹳ, this.ʹ);
        }
    }

    public void ʼ() {
        super.ʼ();
        if (this.ˏ != null) {
            this.ˏ.ˎ(this.ʼ, this.ﹳ, this.ʹ);
        }
    }

    private void ˋ(@NonNull Activity activity) {
        Window window = activity.getWindow();
        if (cgv.ˎ()) {
            View decorView = window.getDecorView();
            decorView.setSystemUiVisibility(5894);
            decorView.setOnSystemUiVisibilityChangeListener(new c(decorView, 5894));
            return;
        }
        window.addFlags(HwAccountConstants.FLAG_TRANS_NAVIGATION_BAR);
        window.addFlags(HwAccountConstants.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
        decorView = window.getDecorView();
        View findViewById = decorView.findViewById(16908335);
        if (findViewById != null) {
            findViewById.setVisibility(8);
        }
        decorView = decorView.findViewById(16908336);
        if (decorView != null) {
            decorView.setVisibility(8);
        }
    }

    private void ˎ(View view) {
        String ʼ;
        if (this.ॱ != null) {
            ʼ = this.ॱ.ʼ();
        } else {
            ʼ = null;
        }
        if (TextUtils.isEmpty(ʼ)) {
            cyq.ˋ.ˊ("SplashScreenFragment", "initImageView: the video file isn't exist, and finish activity.");
            czh.ˋ(this.ˏ, 9);
            czh.ˎ(this.ˏ);
            return;
        }
        this.ʻˊ = new cze(view.getContext());
        this.ʻˊ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ SplashScreenFragment ˎ;

            {
                this.ˎ = r1;
            }

            public void onClick(View view) {
                long currentTimeMillis = System.currentTimeMillis() - this.ˎ.ˎ;
                if (this.ˎ.ˋ < currentTimeMillis) {
                    currentTimeMillis = this.ˎ.ˋ;
                }
                this.ˎ.ˎ(currentTimeMillis);
            }
        });
        this.ﾟ = (VideoPlayer) view.findViewById(a.ˏ);
        this.ﾟ.setController(this.ʻˊ);
        this.ﾟ.setVideoBaseInfo(new b().ˋ(ʼ).ॱ());
        this.ﾟ.ʽ();
    }

    public void ᐝ() {
        super.ᐝ();
        ActivityUtil.unregisterReceiver(ॱˋ(), this.ʻᐝ);
        if (this.ʽ != null) {
            this.ʽ.ˎ();
        }
        if (this.ﾟ != null) {
            this.ﾟ.ˍ();
        }
    }

    private void ॱ() {
        Object obj = null;
        if (this.ॱ != null) {
            Object obj2 = !this.ॱ.ˎ() ? 1 : null;
            FragmentCacheBean ˊ = this.ॱ.ˊ();
            if (!(obj2 == null && (ˊ == null || ˊ.ˏ() == 0))) {
                obj = 1;
            }
            if (!(obj == null || ˊ == null)) {
                this.ˊ = ˊ.ˊ();
                this.ˋ = ˊ.ˊ();
                cyx.ˊ(this.ˊ);
            }
        }
        this.ˊ = cyx.ॱ();
        if (this.ˊ > 0) {
            ʽˊ();
        }
    }

    private void ˊ(View view) {
        TextView textView = (TextView) view.findViewById(a.ʼ);
        if (2 == this.ʹ) {
            textView.setVisibility(0);
        } else {
            textView.setVisibility(8);
        }
        LinearLayout linearLayout = (LinearLayout) view.findViewById(a.ʻ);
        LinearLayout linearLayout2 = (LinearLayout) view.findViewById(a.ˋ);
        linearLayout2.setOnClickListener(this);
        TextView textView2 = (TextView) view.findViewById(a.ˎ);
        this.ﾞ = (TextView) view.findViewById(a.ॱ);
        if (this.ᐝ == 0 && this.ॱॱ == 0) {
            linearLayout2.setVisibility(8);
            linearLayout2.setPadding(0, 0, 0, 0);
            ॱ(linearLayout);
            return;
        }
        if (this.ᐝ == 0) {
            this.ﾞ.setVisibility(8);
            textView2.setPadding(0, 0, 0, 0);
        } else {
            this.ﾞ.setVisibility(0);
        }
        if (this.ॱॱ == 0) {
            textView2.setVisibility(8);
            this.ﾞ.setPadding(0, 0, 0, 0);
        } else {
            textView2.setVisibility(0);
        }
        ॱ(linearLayout);
    }

    private void ॱ(LinearLayout linearLayout) {
        LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
        int dimensionPixelSize = ᐝॱ().getDimensionPixelSize(o.cym.c.ˎ);
        int dimensionPixelSize2 = ᐝॱ().getDimensionPixelSize(o.cym.c.ˏ) + azb.ʽ(cyn.ॱ());
        int i = ᐝॱ().getConfiguration().orientation;
        layoutParams.gravity = 8388661;
        int ˋ = cdo.ˋ(cyn.ॱ());
        if (i == 1) {
            layoutParams.setMarginEnd(dimensionPixelSize2);
            if (2 == this.ʹ) {
                layoutParams.topMargin = ˋ;
                layoutParams.setMarginStart(ˋ(dimensionPixelSize2));
            } else if (epr.ˎ().ॱॱ()) {
                layoutParams.topMargin = ᐝॱ().getDimensionPixelSize(o.cym.c.ˊ) + ˋ;
                layoutParams.setMarginEnd(layoutParams.topMargin);
            } else {
                layoutParams.topMargin = dimensionPixelSize;
            }
        } else {
            i = cdo.ॱ(cyn.ॱ()) - cdo.ˊ(cyn.ॱ());
            if (i == 0) {
                i = dimensionPixelSize;
            } else {
                dimensionPixelSize2 = i;
                i = ˋ;
            }
            layoutParams.setMarginEnd(dimensionPixelSize2);
            layoutParams.topMargin = i;
        }
        linearLayout.setLayoutParams(layoutParams);
    }

    private int ˋ(int i) {
        return (ᐝॱ().getDimensionPixelSize(o.cym.c.ᐝ) + i) + ᐝॱ().getDimensionPixelSize(o.cym.c.ˋ);
    }

    private void ˋ(View view) {
        if (1 == this.ʹ) {
            String ʼ = this.ॱ != null ? this.ॱ.ʼ() : null;
            if (TextUtils.isEmpty(ʼ)) {
                cyq.ˋ.ˊ("SplashScreenFragment", "initImageView: the gif file isn't exist, and finish activity.");
                czh.ˋ(this.ˏ, 9);
                czh.ˎ(this.ˏ);
                return;
            }
            this.ʼˊ = (ImageView) view.findViewById(a.ˊ);
            this.ʼˊ.setScaleType(ScaleType.CENTER_CROP);
            view.setBackgroundColor(-16777216);
            czd.ˋ(this.ʼˊ, ʼ);
            this.ʼˊ.setOnClickListener(this);
        } else if (this.ʹ == 0) {
            Bitmap ॱ = this.ॱ != null ? this.ॱ.ॱ() : null;
            if (ॱ != null) {
                ImageView imageView = (ImageView) view.findViewById(a.ˊ);
                imageView.setImageBitmap(ॱ);
                imageView.setOnClickListener(this);
                imageView.setSystemUiVisibility(4);
                return;
            }
            cyq.ˋ.ˊ("SplashScreenFragment", "initImageView: the image file isn't exist, and finish activity.");
            czh.ˋ(this.ˏ, 9);
            czh.ˎ(this.ˏ);
        }
    }

    private void ʽˊ() {
        if (this.ʽ != null) {
            this.ʽ.ˎ();
        }
        this.ʽ = new czc(this, this.ˊ + 100, 1000) {
            final /* synthetic */ SplashScreenFragment ˏ;

            public void ˊ(long j) {
                this.ˏ.ˊ = j;
                cyx.ˊ(this.ˏ.ˊ);
                if ((this.ˏ.ॱˋ() == null || this.ˏ.ॱˋ().isFinishing()) && this.ˏ.ʽ != null) {
                    this.ˏ.ʽ.ˎ();
                }
                if (this.ˏ.ᐝ != 0) {
                    int i = ((int) j) / 1000;
                    if (this.ˏ.ﾞ != null) {
                        this.ˏ.ﾞ.setText(cgy.ˎ((double) i));
                    }
                }
            }

            public void ˏ() {
                if (this.ˏ.ॱˋ() != null && !this.ˏ.ॱˋ().isFinishing() && this.ˏ.ˏ != null) {
                    this.ˏ.ˏ.ˎ(this.ˏ.ʼ, this.ˏ.ﹳ, this.ˏ.ˋ, this.ˏ.ʹ);
                    this.ˏ.ʽᐝ();
                }
            }
        };
        this.ʽ.ॱ();
    }

    public void onClick(View view) {
        long currentTimeMillis = System.currentTimeMillis() - this.ˎ;
        if (this.ˋ < currentTimeMillis) {
            currentTimeMillis = this.ˋ;
        }
        if (view.getId() != a.ˋ) {
            ˎ(currentTimeMillis);
        } else if (this.ॱॱ != 0) {
            if (this.ʽ != null) {
                this.ʽ.ˎ();
            }
            if (this.ˏ != null) {
                this.ˏ.ˋ(this.ʼ, this.ﹳ, currentTimeMillis, this.ʹ);
            }
            ʽᐝ();
        }
    }

    private void ˎ(long j) {
        if (!TextUtils.isEmpty(czj.ˊ(this.ʼ))) {
            if (this.ʽ != null) {
                this.ʽ.ˎ();
            }
            if (this.ˏ != null) {
                this.ˏ.ˋ(this.ʼ, this.ﹳ, j, this.ʹ, this.ʼˋ, this.ʻˋ);
            }
            ʽᐝ();
        }
    }

    private void ʼᐝ() {
        if (1 == this.ʹ && this.ʼˊ != null) {
            czd.ˋ(this.ʼˊ);
        }
    }

    private void ʽᐝ() {
        if (this.ॱ != null) {
            this.ॱ.ʻ();
        }
        cyx.ʽ();
        ʼᐝ();
    }
}
